﻿using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using System.Windows;

namespace AppToolkit.WPF.UI
{
    /// <summary>
    /// Utilities around localizing WPF UIs.
    /// </summary>
    public class Localization
    {
        /// <summary>
        /// Sets the passed culture as the current threads UI culture.
        /// </summary>
        /// <param name="cultureInfoName"></param>
        public static void SetCulture(string cultureInfoName)
        {
            Contract.Requires<ArgumentException>(!string.IsNullOrWhiteSpace(cultureInfoName), "cultureInfoName");

            var culture = System.Globalization.CultureInfo.GetCultureInfo(cultureInfoName);
            System.Threading.Thread.CurrentThread.CurrentCulture = culture;
            System.Threading.Thread.CurrentThread.CurrentUICulture = culture;

            FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement),
                new FrameworkPropertyMetadata(System.Windows.Markup.XmlLanguage.GetLanguage(System.Globalization.CultureInfo.CurrentCulture.IetfLanguageTag)));

        }
    }
}
